<?php

namespace app;

error_reporting(E_ALL ^ (E_WARNING | E_NOTICE));
@session_start();
// ini_set("session.cookie_httponly", 1);
header("Content-type:text/html;charset=utf-8");

if (!is_file('install.lock')) {
  header('location:install/');
  exit;
}

include_once 'library/inc.php';

$s = iif(str_safe($_GET['s']), DEFAULT_MODULE);
$m = iif(str_safe($_GET['m']), 'index');
$c = iif(str_safe($_GET['c']), 'index');
$id = intval($_REQUEST['id']);

// 引入模块文件
$path = MODULE_DIR . DIRECTORY_SEPARATOR . $s . DIRECTORY_SEPARATOR . MODEL_DIR . DIRECTORY_SEPARATOR;

if (is_file($path . $m . '.php')) {
  include $path . $m . '.php';
} else {
  \Logger::log('index_log', "IP:" . \get_ip() . " Info:" . \get_url_real());
  die($GLOBALS['lang']['404']);
}


// 添加模块namespace并首字母大写
$mod = "app\\" . $s . "\\" . MODEL_DIR . "\\" . ucfirst($m);
// 模块内不存在对应类报非法
if (!class_exists($mod)) {
  \Logger::log('index_log', "IP:" . \get_ip() . " Info:" . \get_url_real());
  die($GLOBALS['lang']['illegal']);
}

// 声明模块类
$api = new $mod();
if (!\method_exists($api, $c)) {
  \Logger::log('index_log', "IP:" . \get_ip() . " Info:" . \get_url_real());
  die($GLOBALS['lang']['illegal']);
}

$api->{$c}($m, $c);